$(function() {
	initPage();
	initButton();
});

// 初始化页面
function initPage() {
	//初始化显得是的茶人茶艺在数据库存的type为2
	$.ajax({
		type : "get",
		url : server_url
				+ 'rest/tea/pay/getBalance.do?ran=' + Math.random(),
		dataType : 'json',
		async : true,
		data : {
			userId:localStorage.getItem('userid')
		},
		success : function(result) {
			//console.log(result);
			if (result.retCode == '0000') {
				$(".my-money").html(result.data);
			} else{
				showErrorMsg(result.data);
			}
		}
	});
}


/**
 * 点击事件
 */
function initButton() {
	$("#recharge").bind('click', function() {
		$('.mask, .buy-pop').css({
			'display': 'block'
		})		
	});	
	
	$("#okpay").bind('click', function() {
		localStorage.setItem("payPrice",$("#payPrice").val());
		window.location = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb0f5fe89c5840bf4&redirect_uri=http://www.nashannacha.com/LianniuWeb/tea/views/pay/recharge.html&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
	});
	
	
	$("#withdrawals").bind('click', function() {
		
		$('.maskwd, .buy-popwd').css({
			'display': 'block'
		})		
	});	
	
	$("#okpaywd").bind('click', function() {
		var myMoney = $(".my-money").html();
		var payPricewd = $("#payPricewd").val();
		localStorage.setItem("payPricewd",$("#payPricewd").val());
//		if(eval(myMoney)>eval(payPrice)){
			window.location = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb0f5fe89c5840bf4&redirect_uri=http://www.nashannacha.com/LianniuWeb/tea/views/pay/withdrawals.html&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
//		}else{
//			alert("提现的钱超过了余额啦!!!");
//		}
	});
}

